package com.sl.au.repository;
import java.util.Date;
import java.util.List;

import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;
import org.springframework.transaction.annotation.Transactional;
import com.sl.au.entity.OperateLog;


@Transactional(readOnly = true)
public interface OperateLogRepository extends JpaRepository<OperateLog, String > {
	///日志的查询
	///没有时间限制
	@Query("select o from OperateLog o where o.user.empLogin.userName like '%'+?1+'%'")
	Page<OperateLog> findLog(String key,Pageable pageable);
	
	@Query("select count(*) from OperateLog o where o.user.empLogin.userName like '%'+?1+'%'")
	long getCount(String key);
	
	///没有起始时间,有结束时间
	@Query("select o from OperateLog o where o.user.empLogin.userName like '%'+?1+'%'"
			+ "and o.createTime <?2")
	Page<OperateLog> findLog(String key,Date endDate,Pageable pageable);
	
	@Query("select count(*) from OperateLog o where o.user.empLogin.userName like '%'+?1+'%'"
			+ "and o.createTime <?2")
	long getCount(String key,Date endDate);
	///起始,结束时间
	@Query("select o from OperateLog o where o.user.empLogin.userName like '%'+?1+'%'"
			+ "and (o.createTime >?2 and o.createTime <?3)")
	Page<OperateLog> findLog(String key, Date startDate,Date endDate,Pageable pageable);
	
	@Query("select count(*) from OperateLog o where o.user.empLogin.userName like '%'+?1+'%'"
			+ "and (o.createTime >?2 and o.createTime <?3)")
	long getCount(String key,Date startDate,Date endDate);
	
	//根据开始时间和结束时间查询日志
	@Query("select a from OperateLog a where a.createTime >= ?1 and a.createTime <= ?2 and a.user.saleArea.superior = ?3 and operateType='登录系统'")
	List<OperateLog> ol(String beginDate,String endDate,String dept);

}
